package com.ruoyi.web.controller.nongjt;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.nongjt.domain.pojo.NjtUserRegister;
import com.ruoyi.nongjt.service.NjtUserRegisterService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nongjt/userRegister")
public class NjtUserRegisterController extends BaseController {

    @Autowired
    private NjtUserRegisterService njtUserRegisterService;

    @PostMapping("/userLogin")
    public AjaxResult userLogin(@RequestBody NjtUserRegister njtUserRegister){
        njtUserRegister = njtUserRegisterService.userLogin(njtUserRegister);
        return AjaxResult.success(njtUserRegister);
    }

    //分页查询列表
    @GetMapping("/list")
    public TableDataInfo getNjtUserRegisterList(NjtUserRegister njtUserRegister){
        startPage();
        List<NjtUserRegister> njtUserRegisterList = njtUserRegisterService.getNjtUserRegisterList(njtUserRegister);
        return getDataTable(njtUserRegisterList);
    }

    //编辑处理，获取表单的数据，更新到数据库
    @PostMapping("/updateUserRegister")
    public AjaxResult updateUserRegister(@RequestBody NjtUserRegister njtUserRegister){
        int rows =  njtUserRegisterService.updateUserRegister(njtUserRegister);
        return toAjax(rows);
    }
    //通过id删除用户信息
    @DeleteMapping("/alterUserRegister/{id}")
    public AjaxResult deleteUserRegister(@PathVariable Long id){
        int rows =  njtUserRegisterService.deleteUserRegister(id);
        return toAjax(rows);
    }

    @PostMapping("/export")
    public void export(HttpServletResponse response, NjtUserRegister njtUserRegister) {
        List<NjtUserRegister> list = njtUserRegisterService.getNjtUserRegisterList(njtUserRegister);
        ExcelUtil<NjtUserRegister> util = new ExcelUtil<NjtUserRegister>(NjtUserRegister.class);
        util.exportExcel(response, list, "用户数据");
    }
}
